function [max_action, max_reward] = SamplePolicy(P,S,mode, policy)

global num_players_r;
global num_players_b;

if(P{2}=='r')
    num_players = num_players_r;
    num_opponents = num_players_b;
else
    num_players = num_players_b;
    num_opponents = num_players_r;
end

P_num = P{3};

if(PlayerInPossession(P,S,mode)) % choose between Dribble and PassBall(k)
    range = [(1:P_num), (P_num+2:num_players+1)];
    [max_action, max_reward] = FindBestAction(P, S, mode,range,policy);
else
    if(TeamInPossession(P,S,mode)) % choose GetOpen and (perhaps) stand still
        range = [2 + num_players, 1 + P_num];
       [max_action, max_reward] = FindBestAction(P, S, mode,range,policy);
    elseif(OpponentInPossession(P,S,mode)) % choose between GoToBall, BlockPass(k)
        range = (3+num_players):(3+num_players+num_opponents);
        [max_action, max_reward] = FindBestAction(P,S,mode,range, policy);
    else % choose between GetOpen and GoToBall and BlockPass
        if(IsClosest(P,S,mode))
            max_action = 3 + num_players;
            F = GetFeatures(P,S,mode,max_action);
            max_reward = Qvalue(F, policy(P_num,:));
        else
            range = [2+num_players, 4+num_players:3+num_players+num_opponents];
            [max_action, max_reward] = FindBestAction(P,S,mode,range, policy);
        end
    end
end

output = ActionToString(max_action, max_reward, num_players, num_opponents);

end